Crate webc

source ·
Expand description

A library for reading and writing WEBC files.

The Container provides an abstraction over the various WEBC versions this crate can handle. As such, it tries to cater to the lowest common denominator and favors portability over performance or power.

In general, errors that occur during lazy operations won’t be accessible to the user.

If more flexibility is required, consider using crate::detect() and instantiating a compatible parser directly.

use webc::{
    Container,
    Version,
    v2::read::OwnedReader,
    v1::{ParseOptions, WebC},
};
let bytes: &[u8] = b"...";

match webc::detect(bytes) {
    Ok(Version::V1) => {
        let options = ParseOptions::default();
        let webc = WebC::parse(bytes, &options).unwrap();
        if let Some(signature) = webc.signature {
            println!("Package signature: {:?}", signature);
        }
    }
    Ok(Version::V2) => {
        let webc = OwnedReader::parse(bytes).unwrap();
        let index = webc.index();
        let signature = &index.signature;
        if !signature.is_none() {
            println!("Package signature: {signature:?}");
        }
    }
    Ok(other) => todo!("Unsupported version, {other}"),
    Err(e) => todo!("An error occurred: {e}"),
}

Re-exports

Modules

  • compatDeprecated
    A compatibility layer for dealing with different versions of the WEBC binary format.
  • Package metadata.
  • Parsing code for v1 of the WEBC format.
  • Parsing code for v2 of the WEBC format.
  • Load a Wasmer package from disk.

Structs

  • A version-agnostic read-only WEBC container.
  • a cheaply cloneable path segment (i.e. the path, to, and file.txt in path/to/file.txt).
  • A series of PathSegments specifying the absolute path to something.
  • A WEBC file’s version number.
  • A WEBC volume.

Enums

Constants

  • File identification bytes stored at the beginning of the file.

Traits

Functions

  • Check whether something looks like a valid WEBC file and extract its version number.
  • Check if the provided item looks like a WEBC file.

Type Aliases